package dp;

import java.util.Arrays;

public class dp279 {
    public static void main(String[] args) {
        System.out.println(numSquares(13));
    }
    public static int numSquares(int n) {
        int[] dp = new int[n + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i <= Math.sqrt(n); i++) {
                for (int j = i * i; j <= n; j++) {
                    dp[j] = Math.min(dp[j - i * i] + 1, dp[j]);
                }
        }
        return dp[n];
    }
}
